package com.saydc.forms.evaluaciones;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;

public class CargaEvaluacionForm extends ActionForm{

	private static final long serialVersionUID = 1L;
	private FormFile file;
	private int tipo;

	
	public FormFile getFile() {
		return file;
	}
	public void setFile(FormFile file) {
		this.file = file;
	}
	public int getTipo() {
		return tipo;
	}
	public void setTipo(int tipo) {
		this.tipo = tipo;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if (file.getFileSize() == 0) {
			errors.add("file", new ActionMessage("error.file.required"));
		} else if (!file.getContentType().equals("application/vnd.ms-excel") && 
					(!file.getContentType().equals("application/pdf"))) {
			errors.add("file", new ActionMessage("error.file.type"));
		}
		/**
		* If the file size is greater than 10mb.
		*/
		else if (file.getFileSize() > 10485760) {
			errors.add("file", new ActionMessage("error.file.size"));
		}
		if(tipo == -1){
			errors.add("tipoFormulario", new ActionMessage("error.evaluacion.tipoEvaluacion"));
		}
		return errors;
	}
	
}
